import mongoose, { connect, disconnect, model, Schema } from "mongoose";

async function main() {
  try {
    mongoose.set("strictQuery", true);
    await connect("mongodb://127.0.0.1:27017/hello");
    console.log("[egg-mongoose] connected successfully");
    /* const ProductionScheme = new Schema({
      name: { type: String },
      price: { type: Number },
    });
    const ProudctModal = model("Product", ProductionScheme);
    const result = await ProudctModal.create({
      name: "cellphone",
      price: 1300,
    });
    const ipad = new ProudctModal({
      name: "ipad",
      price: 4000,
    });
    await ipad.save();
    console.log(result); */

    const UserScheme = new Schema(
      {
        name: { type: String },
        age: { type: Number },
        hobbies: { type: Array },
        team: { type: Schema.Types.ObjectId, ref: "Team" },
      },
      { collection: "user" }
    );
    const UserModel = model("User", UserScheme);
    const result = await UserModel.find({ age: { $gt: 30 } }).exec();
    console.log(result);
  } catch (error) {
    console.error(error);
  } finally {
    await disconnect();
  }
}

main();
